package com.llxwz.event;

import com.alibaba.fastjson.JSONObject;
import com.llxwz.entity.Event;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class EventProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    // 处理事件
    public void fireEvent(Event event) {
        // 将事件发布到指定的主题
        rabbitTemplate.convertAndSend(event.getExchangeName(),event.getRouteName(),JSONObject.toJSONString(event));
    }

}
